﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Edge.Business.Domain.Application;
using Edge.Common.ComponentModel.Parameters;
using Edge.Common.Services;
using Shop.Business.Domain.Customers;

namespace Shop.Web.Controls.Ajax
{
    public partial class AddresList : System.Web.UI.UserControl
    {
        [QueryParameter("id", IsRequired = false)]
        public int customerId = -1;


        public string DftAddres;

        private Customer currentCustomer;
        
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            WebParameterAttribute.SetValues(this, Request);
            if (Locator.GetService<IContextObjects>().Get<CustomerHolder>() != null)
            {
                currentCustomer = Locator.GetService<IContextObjects>().Get<CustomerHolder>().Object;
                if (customerId > 0)
                {
                    currentCustomer = Locator.GetService<ICustomerManager>().Load(customerId);
                }
                DftAddres = currentCustomer.DefaultAddress != null ? currentCustomer.DefaultAddress.Id.ToString() : "";
                rprAddressList.DataSource = currentCustomer.Address;
                rprAddressList.DataBind();
            }
            base.OnPreRender(e);
        }

    }
}